//
//  SISSHomeFunctionView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/14.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSHomeFunctionView.h"
#import "SISSButton.h"

@implementation SISSHomeFunctionView


- (void)initUI {
    [super initUI];
    
    self.backgroundColor = [UIColor whiteColor];
 
    NSArray *iconName = @[@"房源", @"客源", @"合作", @"地图", @"百科", @"出租", @"租客", @"新房", @"房价地图"];
    NSArray *name = @[@"找房源", @"找客源", @"找合作", @"需求地图", @"买房百科", @"找出租", @"找租客", @"找新房", @"房价地图"];
    
    // 循环创建四个按钮
    for (int i = 0; i < name.count; i++) {
        
        SISSButton *button = [SISSButton buttonWithType:UIButtonTypeCustom];
        
       
//        CGFloat btnY = 0;
//        CGFloat btnX = SCREEN_WIDTH * 0.5 + SCREEN_WIDTH * 0.25 * (i - 2) + 6 * MAIN_SCALE;
//        button.frame = CGRectMake(btnX, btnY, 84, 84);
        [button setImage:[UIImage imageNamed:iconName[i]] forState:UIControlStateNormal];
        [button setTitle:name[i] forState:UIControlStateNormal];
        [button setTintColor:COLOR(0x334A60)];
        [button setTitleColor:COLOR(0x334A60) forState:UIControlStateNormal];
        
        button.tag = i;
        [button addTarget:self action:@selector(buttonDidClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:button];
        
        if (i > 4) {
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self).offset(84);
                make.left.equalTo(self).offset(SCREEN_WIDTH * 0.2 * (i - 5));
                make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH * 0.2, 84));
            }];
        } else {
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self);
                make.left.equalTo(self).offset(SCREEN_WIDTH * 0.2 * i);
                make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH * 0.2, 84));
            }];
        }
    }
}

/**
 功能按钮点击事件
 */
- (void)buttonDidClick:(SISSButton *)button {
    
    // 代理回调
    if ([self.delegate respondsToSelector:@selector(homeFunctionButtonClickAtIndex:)]) {
        [self.delegate homeFunctionButtonClickAtIndex:button.tag];
    }
}

@end
